Skip to content

User Interface for Adjusting Game Preferences#4

Open
albertliangcode wants to merge 2 commits intoAdamYee:masterfrom
albertliangcode:master
Open

User Interface for Adjusting Game Preferences#4
albertliangcode wants to merge 2 commits intoAdamYee:masterfrom
albertliangcode:master

Conversation

@albertliangcode
Copy link
Contributor

This is just so that you can track me as I keep tinkering with the code. Classes start on January 4th, so I may not be able to spend much time on this in the coming weeks. Please don't feel rushed to reply to anything I write - I'll keep shuffling along!

// Adjust Dimensions of Base
var edgeThickness = 2 * (parseInt($(".cell").css("border-left-width")) + parseInt($(".cell").css("margin")) + parseInt($(".cell").css("padding")));
$(".base").height(numRow * ($(".cell").height() + edgeThickness) + 10);
$(".base").width(numCol * ($(".cell").width() + edgeThickness) + 10);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You won't need to do these hacks if you apply the proper CSS rules to the board and cells. Delete the above 3 lines after adding these styles.

.base {
    display: inline-block; /* inline block will remove the grey space to the right - that's the difference between block and inline-block */
    padding: 5px; /* this will compensate for the removing of top/left styles */
    background-color: gray;
}
.cell {
    background-color: blue;
    height: 30px;
    width: 30px;
    position: relative;
    display: inline-block; /* <------------ Remove this because you override with display: flex below */
    margin: 2px;
    padding: 2px;
    text-align: center;
    color: blue;
    left: 5px; /* <------------ Remove this */

    display: flex; 
    align-items: center; 
    justify-content: center; 
}
.row {
    display: block;
    border: 0px;
    position: relative;
    top: 5px; /* <------------ Remove this */
    display: flex;
}

@AdamYee
Copy link
Owner

AdamYee commented Jan 15, 2015

After I locally fixed the above issues, I found another:

ui.js manipulates the grid HTML, you have to bind the .mousedown handler AFTER the dom has been created and added to the page. With the way the code is written, this means that you need to move the .mousedown logic to inside the .submit handler. In other words, when the button is clicked, inside the submit handler 1) create the grid 2) bind .mousedown handler - so a nested handler. Without this, the grid will be created, but clicking on the cells does nothing.

Once these things are resolved, then the next step is to decouple jquery code. It's very tempting to just use $ anywhere in your code, but this leads to spaghetti jquery code which is hard to debug, maintain and extend.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments